<?php

class ArticleModel extends Model{

	public $validate = array(

		);
	// public $auto = array(
	// 	array('sendtime','strtotime','function',2,3),
	// 	);
	public $auto = array(
		array('sendtime','changetime','method',2,3),
		);
	public function changetime($v){
		//$v sendtime 表单项 post中的值
		return strtotime($v);
	}

	public function addArticle(){
		// p($this->data);
		if($this->create()){
			//经过create处理之后，合法数据会被压入到 $this->data中。add() save() update()等方法不添加参数时默认用$this->data
			// p($this->data);die;
			if($aid = $this->add()){
				return $aid;
			}else{
				return false;
			}
		}
	}

	/*
	*	根据aid 获取文章数据
	*/
	public function getDataByAid($aid=null){
		$aid = isset($aid) ? $aid : Q('aid',0,'intval');
		$where = array('aid'=>$aid);
		return $this->where($where)->find();
	}

	/*
	*	编辑文章
	*/
	public function saveArticle(){
		$aid = Q('aid',0,'intval');
		if($this->create()){
			$where = array('aid'=>$aid);
			$this->where($where)->save();
			K('ArticleTags')->editData($aid);
			return true;
		}
	}

}

?>